<?php
/**
 * 不使用队列的,快速响应客户端
 */
register_shutdown_function('faster');
function fast($fast = null, $par = array())
{
    if (!$fast) {
        echo PHP_SAPI;
        file_put_contents('/Users/jiangyong/whole/data/wwwroot/fast.log',PHP_SAPI . "\n", FILE_APPEND);
        $_ENV['shutdown'] = 1;
        set_time_limit(0);
        if (isset($_ENV['faster']) && is_array($_ENV['faster']) && $_ENV['faster']) {
            foreach ($_ENV['faster'] as $k => $v) {
                call_user_func_array($k, $v);
                unset($_ENV['faster'][$k]);
            }
        }
    } elseif (isset($_ENV['shutdown'])) call_user_func_array($fast, $par);
    else $_ENV['faster'][$fast] = $par;
}

/**
 * fastcgi_finish_request
 */
function faster()
{
	echo PHP_SAPI;
    if (isset($_ENV['shutdown'])) {
        return;
    }
    if (
        //'cli' !== PHP_SAPI && 
        function_exists('fastcgi_finish_request')
    ) {
        var_dump( function_exists('fastcgi_finish_request'));
        fastcgi_finish_request();
        $_ENV['shutdown'] = 1;
    }
    fast();
}

function mq() {
	echo '-------after request-----end-----';
};

fast('mq', []);
echo 'ok';